import { defineStore } from 'pinia';
import mineApi from "../apis/mine";

export const playingStore = defineStore('playing', {
  state: () => {
    return {
      toolObj:null,
      scaleDisplay:true,
      isDisplay:false,
      data: {}
    };
  },
  actions: {
    //获取当前是否在房间中
    async handleGetRoomInfo(){
      let res = await mineApi.getRoomInfo();
      if(res.code == 'SUCCESS' && res.data){
        let arr = res.data.filter((item)=>{
          return item;//.status == 'PLAYING'
        })
        if(arr.length){
          this.isDisplay = true;
          this.setPlaying(arr[0]);
        }else{
          this.closePlaying();
        }
      }
    },
    //启动
    startLoop(){
      this.handleGetRoomInfo();
      /*clearInterval(this.toolObj);
      this.toolObj = setInterval(()=>{
        this.handleGetRoomInfo();
      },3500);*/
    },
    setScale(){
      this.scaleDisplay = !this.scaleDisplay;
    },
    setPlaying(data) {
      this.isDisplay = true;
      this.data = data
    },
    closePlaying() {
      //clearInterval(this.toolObj);
      this.isDisplay = false;
      this.data = {}
    }
  }
});
